import request from '@/utils/request'
const ThirdWechatQrcodeService = {
  state: {},

  mutations: {},

  actions: {
    /**
     * 二维码 分页
     */
    thirdWechatQrcodePage({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.get('thirdWechatQrcode/page', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    /**
    * 根据主键获得二维码
    */
    thirdWechatQrcodeGetById({ commit }, id) {
      return new Promise((resolve, reject) => {
        request.get('thirdWechatQrcode/getById/' + id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    /**
    * 根据主键获得二维码 详情
    */
    thirdWechatQrcodeGetDetailsById({ commit }, id) {
      return new Promise((resolve, reject) => {
        request.get('thirdWechatQrcode/getDetailsById/' + id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    /**
     * 二维码 保存
     */
    thirdWechatQrcodeSave({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('thirdWechatQrcode/save', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    /**
     * 二维码 更新
     */
    thirdWechatQrcodeUpdate({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('thirdWechatQrcode/update/' + params.id, params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    /**
     * 二维码 删除
     */
    thirdWechatQrcodeRemove({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('thirdWechatQrcode/remove', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 微信二维码生成
    generateWechatQrCode({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.pictureStream('thirdWechatQrcode/generateQrCode/' + params.id, { appId: params.appId }).then(response => {
          const data = response
          resolve('data:image/png;base64,' + btoa(new Uint8Array(data).reduce((data, byte) => data + String.fromCharCode(byte), '')))
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default ThirdWechatQrcodeService
